#include <iostream>  
#include <vector>  
#include <string>  
#include <stack>  
#include <algorithm>  
  
using namespace std;  
  
struct Grades {  
    string name;  
    string lesson;  
    int grade;  
};  
  
vector<Grades> allGrades;  
stack<string> operations;  
  
void addGrade(const string& name, const string& lesson, int grade) {  
    Grades newGrade = {name, lesson, grade};  
    allGrades.push_back(newGrade);  
    operations.push("添加 学生成绩 " + name + " ， " + lesson + " ， " + to_string(grade));  
}  
  
void displayGrades(bool ascending = true) {  
    if (ascending) {  
        sort(allGrades.begin(), allGrades.end(), [](const Grades& a, const Grades& b) {  
            return a.name < b.name;  
        });  
    } else {  
        sort(allGrades.begin(), allGrades.end(), [](const Grades& a, const Grades& b) {  
            return a.name > b.name;  
        });  
    }  
  
    for (const auto& grade : allGrades) {  
        cout << "学生姓名: " << grade.name << " ， 课程名: " << grade.lesson << " ， 成绩: " << grade.grade << endl;  
    }  
}  
  
int main() {  
    string name, lesson;  
    int grade;  
    char continueInput = 'y';  
  
    while (continueInput == 'y' || continueInput == 'Y') {  
        // 录入学生成绩  
        cout << "请输入学生姓名: ";  
        getline(cin, name);  
        cout << "请输入课程名: ";  
        getline(cin, lesson);  
        cout << "请输入成绩: ";  
        cin >> grade;  
        cin.ignore(); // 忽略输入缓冲区中的换行符  
  
        addGrade(name, lesson, grade);  
  
        cout << "是否继续输入学生成绩? (y/n): ";  
        cin >> continueInput;  
        cin.ignore(); // 忽略输入缓冲区中的换行符  
    }  
  
    // 显示所有学生成绩  
    cout << "所有学生成绩: " << endl;  
    displayGrades(true);  
  
    
  
    return 0;  
}